package com.isunny.mode.tactics.factory;

import com.isunny.mode.tactics.strategy.EvictionStrategy;
import com.isunny.mode.tactics.EvictionType;
import com.isunny.mode.tactics.strategy.FifoEvictionStrategy;
import com.isunny.mode.tactics.strategy.LfuEvictionStrategy;
import com.isunny.mode.tactics.strategy.LruEvictionStrategy;

/**
 * 配置工厂
 *
 * @author luom
 * @date 2022/2/25
 */
public class EvictionStrategyPrototypeFactory {

    public static EvictionStrategy getEvictionStrategy(EvictionType evictionType) {
        if (evictionType == null) {
            throw new IllegalArgumentException("evictionType should not be null");
        }

        if (evictionType == EvictionType.FIFO) {
            return new FifoEvictionStrategy();
        } else if (evictionType == EvictionType.LFU) {
            return new LfuEvictionStrategy();
        } else if (evictionType == EvictionType.LRU) {
            return new LruEvictionStrategy();
        } else {
            throw new UnsupportedOperationException("evictionType not found");
        }
    }
}
